#!/usr/bin/python3

#########################################
## WGCLT (WebGet CopyLeft Tool) v0.4.b ##
## Old name PyGet                      ##
## GNU GPL License                     ##
#########################################


import requests
from sys import argv

try:
    from rich.console import Console
except:
    print("[-] Rich library not found! Install it with next command: pip install rich.")

con = Console()

try:
    url = str(argv[1])
except IndexError:
    print(f" Usage: {str(argv[0])} url\n")
    quit()

## Get page
try:
    page = requests.get(url)
except:
    con.print(" [red bold]\[-][/red bold] Not corect url or another error")
    exit()


## Code errors
if page.status_code == "401":
    con.print(" [red bold]\[-][/red bold] You're not authorized!")
    quit()

if page.status_code == "403":
    con.print(" [red bold]\[-][/red bold] Server forbbiden access to page!")
    quit()

if page.status_code == "404":
    con.print(" [red bold]\[-][/red bold] Page not found!")
    quit()


con.print(" [cyan bold]\[+][/cyan bold] Done!")
file_name = url.split('/')
file_name = file_name[-1]
if file_name == '':
	file_name = 'index.html'


## Save page
file = open(f'wgclt_{file_name}', 'w')
file.write(page.text)
file.close()

con.print(f" [cyan bold]\[+][/cyan bold] Page downloaded")
